<template>
  <div class="search">
    <el-form :model="searchForm" ref="formRef" label-width="80px" size="large">
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="用户名" prop="name">
            <el-input
              v-model="searchForm.name"
              placeholder="请输入查询用户名"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="真实姓名" prop="realname">
            <el-input
              v-model="searchForm.realname"
              placeholder="请输入查询真实姓名"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="电话号码" prop="cellphone">
            <el-input
              v-model="searchForm.cellphone"
              placeholder="请输入查询电话号码"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="状态" prop="enable">
            <el-select
              v-model="searchForm.enable"
              style="width: 100%"
              placeholder="请选择查询状态"
            >
              <el-option label="启用" :value="1" />
              <el-option label="禁用" :value="0" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="创建时间" prop="createAt">
            <el-date-picker
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              v-model="searchForm.createAt"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <!-- 重置和搜索 -->
    <div class="btn">
      <el-button @click="handleResetClick" icon="Refresh" size="large"
        >重置</el-button
      >
      <el-button
        @click="handleQueryClick"
        icon="Search"
        size="large"
        type="primary"
        >查询</el-button
      >
    </div>
  </div>
</template>
<script setup lang="ts">
import type { ElForm } from 'element-plus'
import { reactive, ref } from 'vue'
const emit = defineEmits(['queryClick', 'resetClick'])

// 字段名和服务器一致
const searchForm = reactive({
  name: '',
  realname: '',
  cellphone: '',
  enable: 1,
  createAt: ''
})
// 重置 拿到实例对象
const formRef = ref<InstanceType<typeof ElForm>>()
function handleResetClick() {
  // searchForm.name = '' 手动重置或者调用方法。
  formRef.value?.resetFields()
  emit('resetClick')
}
// 发送给父组件事件

// 查询
function handleQueryClick() {
  // console.log('查询', searchForm)
  emit('queryClick', searchForm)
}
</script>
<style lang="less" scoped>
.search {
  background-color: #fff;
  padding: 20px;
  .el-form-item {
    padding: 10px;
    margin-bottom: 0;
  }
  .btn {
    text-align: right;
    .el-button {
      height: 36px;
    }
  }
}
</style>
